package day06;

import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) {
        while (true) {
            int months = 0;
            int year = yearcs();
            System.out.println("输入月份：");
            Scanner cs = new Scanner(System.in);
            months = cs.nextInt();

            if (isLeapYear(year)) {
                System.out.println(year + " 是闰年");
            } else {
                System.out.println(year + " 不是闰年");
            }
            getDaysInMonth(months, isLeapYear(year));

        }
    }

    public static boolean isLeapYear(int year) {
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
            return true;
        } else {
            return false;
        }
    }

    public static int yearcs() {
        int year = 6;
        System.out.println("请输入一个年份,输入0退出程序:");
        Scanner cs = new Scanner(System.in);
        while ((year >= 0 && year < 1900) || year > 2050) {
            year = cs.nextInt();
            if (year == 0) {
                System.exit(0);

            }
            System.out.println("输入的年份不合法,请重新输入！");
        }

        return year;

    }

    public static int getDaysInMonth(int month, boolean isLeapYear) {
        int days = 0;
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                System.out.println(month + "月" + "31天");
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                System.out.println(month + "月" + "30天");
                break;
            case 2:
                System.out.println(month + "月" + (isLeapYear ? 29 : 28) + "天");
                break;
            default:
                System.out.println("输入的月份不合法!");
        }
        return days;

    }
}
